<template>
	<view class="index-content">
		<TopBar :indexflag="true" :combakflag="true" :lang="false" :bottom="true" :title="$t('Statistics')"
			:barstyle="colortopic()" Color="#fff"></TopBar>
		<view class="top-time">
			<text>{{timestampToDate(Startvalue)}}</text>
			<text> ----- </text>
			<text> {{timestampToDate(Endvalue)}}</text>
		</view>
		<view class="order-list">
			<scroll-view scroll-y="true" style="height:100%;width:100%" @scrolltolower="scrolldata">
				<!-- 我的订单 -->
				<view class="" v-if="!orderList.length" style="height:200rpx"></view>
				<u-empty v-if="orderList.length==0" style="padding-top: 200rpx;" mode="order" iconSize="100"
					textSize="14" :text="$t('OrderEmpty')">
				</u-empty>
				<view class="list" v-if="orderList.length" :style="{direction:i18nLocale=='ug'?'rtl':''}"
					v-for="(item,index) in orderList" @click="handdetail(item.id)">
					<!-- <view class="">{{item.order.out_trade_no}}</view> -->
					<view class="time">
						<text>{{$t('TimePlaced')}}:</text>
						{{item.paid_at?item.paid_at:item.created_at}}
						<u-icon name="checkmark-circle-fill" :color="colortopic()" size="25" v-if="item.status==1"></u-icon>
						<u-icon name="qzone-circle-fill" :color="colortopic()" size="25" v-if="item.status==0"></u-icon>
					</view>
					<view class="totalprice-box">
						<text>{{$t('OrderType')}}</text>
						<text class="served" v-if="item.status==0 || item.status==null"
							@click.stop="changefinsh(item.id,'status')">{{$t('Served')}}</text>
						<text class="order-type" v-if="item.status==0">{{$t('New')}}</text>
						<text class="order-type" style="color:#999" v-if="item.status==1">{{$t('ServedYes')}}</text>
					</view>
					<view class="order-item">
						<view class="table-content">
							<view class="title">{{$t('TableNumber')}}</view>
							<view class="number">{{item.table_number}}</view>
						</view>
						<view class="item" v-for="(subitem,sub_index) in item.items">
							<view class="left">
								<view class="name">{{i18nLocale=='ug'?subitem.ug_name:subitem.cn_name}}</view>
							</view>
							<view class="right">
								<view class="number">X{{subitem.qty}}</view>
								<view class="price">￥{{subitem.price}}</view>
							</view>
						</view>
		
						<view class="totalprice-box">
							<text>{{$t('TotalPrice')}}</text>
							<text class="totalprice">￥{{item.fee}}</text>
						</view>
					</view>
		
				</view>
			</scroll-view>
			<Loading :show="loadshow" iconName="circle" bgZindex="99" bgColor="" :text="$t('Loading')"></Loading>
			<Loading :show="tabloadshow" bgZindex="99" iconName="circle-round" :showText="false"></Loading>
		</view>
	</view>
</template>

<script>
	import {
		getorder,
		orderstatus
	} from '@/api/shop.js';

	export default {
		components: {
			
		},
		onLoad(e) {
			if (e.startvalue) {
				this.Startvalue = e.startvalue;
				this.Endvalue=e.endvalue;
			}
			this.scrolldata();
		},
		data() {
			return {
				acnav: 0,
				orderList: [],
				pageSize: 5,
				page: 1,
				total: 0,
				to: 1,
				tabloadshow: false,
				loadshow: false,
				codepop: false,
				code_url: '',
				order_id: '',
				logo: 'https://static.clewm.net/cli/images/cli_logo_new.png',
				Startvalue: Number(new Date().setDate(new Date().getDate() - 1)),
				Endvalue: Number(new Date()),
			}
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
			Neworder() {
				return this.$store.state.neworder;
			},
			Payorder() {
				return this.$store.state.paid;
			}
		},
		watch: {
			Neworder(newName, oldName) {
				if (this.$store.state.shoptoken) {
					this.changeNav('no');
				}
			},
			Payorder(newName, oldName) {
				if (this.$store.state.shoptoken) {
					this.changeNav('no');
				}
			},
		},
		methods: {
			scrolldata() {
				if (this.to != this.total) {
					this.loadshow = true;
					this.getOrders();
				} else {

				}
			},
			handdetail(id) {
				uni.navigateTo({
					url: '/pages/boos/boosorder/orderdatail?id=' + id
				})
			},
			getOrders() {
				let that = this;
				getorder({
					per_page: that.pageSize,
					page: that.page,
					payment_status: 1,
					start: parseInt(that.Startvalue / 1000),
					end: parseInt(that.Endvalue / 1000)
				}).then((res) => {
					if (res.code == 200) {
						let data = res.body;
						that.total = data.total;
						that.to = data.to;
						that.page++;
						let mydata = that.orderList.concat(data.data);
						that.orderList = mydata;
						that.tabloadshow = false;
						that.loadshow = false;
					}
				})
			},
			codeOpen() {},
			codeClose() {
				this.codepop = false;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index-content {
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		
		.top-time{
			width: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.order-list {
			width: 100%;
			height: calc(100% - 120rpx);
			box-sizing: border-box;
			padding: 0rpx 20rpx;

			.list {
				width: 100%;
				background: #FFFFFF;
				box-shadow: $uni-bg-shadow;
				border-radius: $uni-border-radius-lg;
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx 40rpx;
				box-sizing: border-box;

				.time {
					width: 100%;
					padding: 10rpx 0rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					color: #000;

					text {
						color: #808080;
					}

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.order-item {
					width: 100%;
					display: flex;
					flex-direction: column;
					position: relative;

					.item {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 20rpx 0rpx;

						.left {
							display: flex;
							align-items: center;

							image {
								width: 120rpx;
								height: 120rpx;
								border-radius: 20rpx;
							}

							.name {
								color: $uni-color-title;
								font-size: $uni-font-size-base;
								// padding: 0rpx 30rpx;
							}
						}

						.right {
							display: flex;
							align-items: center;

							.price {
								color: $uni-color-topic;
								font-size: $uni-font-size-base;
								// padding: 0rpx 30rpx;
							}

							.number {
								color: $uni-text-color-grey;
								font-size: $uni-font-size-sm1;
								padding: 0rpx 30rpx;
							}

						}

					}

					.totalprice-box {
						display: flex;
						justify-content: space-between;
						align-items: center;
						font-size: $uni-font-size-base;

						.totalprice {
							color: #f4464b;
							font-size: 32rpx;
						}

						.served {
							padding: 7rpx 10rpx;
							border-radius: 10rpx;
							background-color: $uni-color-topic2;
							color: #fff;
							font-size: $uni-font-size-base;
						}

						.order-type {
							// width: 100rpx;
							// height: 100rpx;
							// border-radius: 100%;
							padding: 10rpx;
							display: flex;
							justify-content: center;
							align-items: center;
							// background-color: $uni-color-topic;
							color: $uni-color-topic;
							font-size: $uni-font-size-lg;
						}
					}

					.table-content {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.title {
							font-size: $uni-font-size-base;
						}

						.number {
							width: 60rpx;
							height: 60rpx;
							border-radius: 100%;
							display: flex;
							justify-content: center;
							align-items: center;
							background-color: $uni-color-topic;
							color: #fff;
							font-size: $uni-font-size-lg;
						}
					}

					.button {
						background-color: $uni-color-topic;
						border-radius: $uni-border-radius-lg;
						padding: 20rpx 80rpx;
						margin: 0 auto;
						color: #fff;
					}

					.type-icon {
						position: absolute;
						top: 0%;
						left: 0%;
						transform: rotate(45deg);
						background-color: rgba(0, 0, 0, 0.4);
						color: $uni-color-topic;
						width: 100rpx;
						height: 100rpx;
						border-radius: 100%;
						display: flex;
						justify-content: center;
						align-items: center;
					}


				}

				.totalprice-box {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: $uni-font-size-base;

					.totalprice {
						color: #f4464b;
						font-size: 32rpx;
					}

					.served {
						padding: 7rpx 10rpx;
						border-radius: 10rpx;
						background-color: $uni-color-topic2;
						color: #fff;
						font-size: $uni-font-size-base;
					}

					.order-type {
						// width: 100rpx;
						// height: 100rpx;
						// border-radius: 100%;
						padding: 10rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						// background-color: $uni-color-topic;
						color: $uni-color-topic;
						font-size: $uni-font-size-lg;
					}
				}


			}
		}
	}

	.pop-box {
		height: 630rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 50rpx 60rpx;

		.pop-title {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 20rpx 0rpx;
		}

		.button-grop {
			width: 100%;
			display: flex;
			justify-content: space-around;
			margin-top: 80rpx;
			color: #fff;

			.button {
				border: 1rpx solid #999;
				padding: 10rpx 30rpx;
				border-radius: 20rpx;
				margin: 0rpx 20rpx;
			}
		}
	}
</style>